package com.examples.ry.graphics;

import java.util.Hashtable;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;



public class RectangleExample1 {

	public static void main(String args[]) {
		Display display = new Display();
		final Shell shell = new Shell(display);
		shell.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) {
				Rectangle clientArea = shell.getClientArea();
				e.gc.drawLine(1, 1, clientArea.width-5, clientArea.height-5);
				e.gc.drawRectangle(1, 1, clientArea.width-5, clientArea.height-5);
			}
		});
		shell.setSize(150, 150);
		shell.open();

		Hashtable h = new Hashtable();
		Point p = new Point(100, 100);
		h.put(p, "get the point?");
		p.x = 200; // BAD BAD BAD: changes hashCode of p.
		
		System.out.println("Getting value from hashTable:::"+h.get(p));
		
		Rectangle rect1 = new Rectangle(0,0, 5, 5);
		Rectangle rect2 = new Rectangle(10,10, 70, 70);
		
		System.out.println("rect1 contains point Q1(10,10)::"+ rect1.contains(60,60));
		System.out.println("rect1 intersects(rect2) ::"+ rect1.intersects(rect2));
		System.out.println("rect1 intersection(rect2) ::"+ rect1.intersection(rect2));
		//System.out.println("rect1 intersect(rect2) ::"+ rect1.intersect(rect2));
		System.out.println("rect1 union(rect2) ::"+ rect1.union(rect2));
		

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();

	}

}
